import { configureStore } from '@reduxjs/toolkit'
import {
  useSelector,
  TypedUseSelectorHook,
  useDispatch,
  shallowEqual
} from 'react-redux'
import codeRedecer, { resetStateCreate } from './modules/create'
import successReducer, { resetStateSuc } from './modules/success'
import codeallReducer, { resetStateCodeall } from './modules/codeall'
const store = configureStore({
  reducer: {
    code: codeRedecer,
    success: successReducer,
    codeall: codeallReducer
  }
})

export const resetAllStore = () => (dispatch: typeof store.dispatch) => {
  dispatch(resetStateCodeall())
  dispatch(resetStateCreate())
  dispatch(resetStateSuc())
}

// 将useSelector替换为自定义的useMySelector，这样每次使用时就可以自动识别出当前状态的类型，不需要每次都手动添加
export const useMySelector: TypedUseSelectorHook<
  ReturnType<typeof store.getState>
> = useSelector
export const useMyDispatch = () => useDispatch<typeof store.dispatch>()
export const MyShallEqual = shallowEqual

export default store
